package com.usian.admin.controller.v1;

import com.usian.admin.service.WemediaNewsAutoService;
import com.usian.common.dtos.PageResult;
import com.usian.common.dtos.ResponseResult;
import com.usian.model.admin.dtos.NewsAuthDto;
import com.usian.model.media.dtos.WmNewsResultDTO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author Fay
 * @date 2022/7/14&19:34
 */
@RequestMapping("/api/v1/news_auth")
@RestController
public class NewsAuthController {
    @Autowired
    private WemediaNewsAutoService wemediaNewsAutoService;

    /**
     * 分页查询+模糊查询
     * @param newsAuthDto
     * @return
     */
    @PostMapping("/list")
    public PageResult<WmNewsResultDTO> findWmNewsByPage(@RequestBody NewsAuthDto newsAuthDto){
        return wemediaNewsAutoService.findWmNewsByPage(newsAuthDto);
    }
    /**
     * 根据id查询
     */
    @GetMapping("/one/{id}")
    public ResponseResult<WmNewsResultDTO> findOneWmNews(@PathVariable(name = "id")Integer wmNewsId){
        return wemediaNewsAutoService.findOneWmNews(wmNewsId);
    }
    /**
     * 自媒体人工审核通过
     */
    @PostMapping("/auth_pass")
    public ResponseResult authPass(@RequestBody NewsAuthDto newsAuthDto){
        wemediaNewsAutoService.updateWmNews(newsAuthDto.getId(),"人工审核通过",WmNewsResultDTO.Status.ADMIN_SUCCESS.getCode());
        return ResponseResult.ok();
    }
    /**
     * 自媒体文章人工审核不通过
     * @param newsAuthDto
     * @return
     */
    @PostMapping("/auth_fail")
    public ResponseResult authFail(@RequestBody NewsAuthDto newsAuthDto) {
        wemediaNewsAutoService.updateWmNews(newsAuthDto.getId(),newsAuthDto.getMsg(),WmNewsResultDTO.Status.FAIL.getCode());
        return ResponseResult.ok();
    }
}
